package com.zwx.string.leetcode_3;

/**
 * 有效的字母异位词
 *
 * @author 文希
 * @create 2019-06-30 13:17
 */
public class IsAnagram {

    private static boolean isAnagram(String s, String t) {
        int[] alpha = new int[26];
        for (int i = 0; i < s.length(); i++) {
            alpha[s.charAt(i) - 'a']++;
        }
        for (int i = 0; i < t.length(); i++) {
            alpha[t.charAt(i) - 'a']--;
        }
        for (int i : alpha) {
            if (i != 0) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        String s="anagram";
        String t = "nagaram";
        boolean anagram = isAnagram(s, t);
        System.out.println("anagram = " + anagram);
    }
}
